Skip to content

fix: execute template in expandAlias for -a flag#4

Merged
datamuc merged 3 commits intoConSol-Monitoring:mainfrom
KIBruh:fix/expand-alias
May 8, 2026
Merged

fix: execute template in expandAlias for -a flag#4
datamuc merged 3 commits intoConSol-Monitoring:mainfrom
KIBruh:fix/expand-alias

Conversation

@KIBruh
Copy link
Copy Markdown

@KIBruh KIBruh commented May 5, 2026

The expandAlias function was parsing the template but never executing it, resulting in empty output when using the -a (alias) flag with template syntax. Now properly executes the template with the label map and handles execution errors by falling back to the original alias string.

Fixes alias templates like:

  • check_prometheus m q -a 'Host: {{.hostname}}'
  • check_prometheus m q -a 'Status: {{if eq .xvalue "1"}}UP{{else}}DOWN{{end}}'

Includes comprehensive unit tests covering:

  • Simple label substitution
  • Multiple labels
  • xvalue special variable
  • Conditional logic (if/else)
  • Invalid template fallback

KIBruh added 3 commits May 5, 2026 15:55
The expandAlias function was parsing the template but never executing it,
resulting in empty output when using the -a (alias) flag with template syntax.
Now properly executes the template with the label map and handles execution
errors by falling back to the original alias string.

Fixes alias templates like:
- check_prometheus m q -a 'Host: {{.hostname}}'
- check_prometheus m q -a 'Status: {{if eq .xvalue "1"}}UP{{else}}DOWN{{end}}'

Includes comprehensive unit tests covering:
- Simple label substitution
- Multiple labels
- xvalue special variable
- Conditional logic (if/else)
- Invalid template fallback
Include internal mode in test command.
@datamuc datamuc merged commit 9895441 into ConSol-Monitoring:main May 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants